package org.taohuawu.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.taohuawu.feign.ItemFeignService;
import org.taohuawu.feign.UserFeignService;
import org.taohuawu.pojo.Item;
import org.taohuawu.pojo.Order;
import org.taohuawu.pojo.User;
import org.taohuawu.service.OrderService;
import org.taohuawu.web.util.JsonResult;

import java.util.List;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private ItemFeignService itemFeignService;

    @Autowired
    private UserFeignService userFeignService;

    @Override
    public Order getOrder(String orderId) {
        JsonResult<List<Item>> items = itemFeignService.getItems(orderId);

        JsonResult<User> user = userFeignService.getUser(7);

        Order order = new Order();
        order.setId(orderId);
        order.setItems(items.getData());
        order.setUser(user.getData());
        return order;
    }

    @Override
    public void addOrder(Order order) {
        log.info("保存订单："+order);
    }
}
